<template>
  <div class="goods-item" @click="itemClick">
    <img :src="showImage" alt="" @load="imageLoad">
    <div class="goods-info">
      <p>{{goodsItem.title}}</p>
      <span class="price">{{goodsItem.price}}</span>
      <span class="collect">{{goodsItem.cfav}}</span>
    </div>
  </div>
</template>

<script>
  export default {
    name: 'GoodsListItem',
    props:{
      goodsItem:{
        type:Object,
        default(){
          return {}
        }
      }
    },
    computed:{
      showImage(){
        return this.goodsItem.image || this.goodsItem.show.img
      }
    },
    methods:{
      imageLoad(){
        this.$bus.$emit('itemImgLoad')
        
        //第一种监听全局事件
        // if(this.$route.path.indexOf('/home')){
        //   this.$bus.$emit('homeItemImgLoad')
        // }else if(this.$route.path.indexOf('/detail')){
        //   this.$bus.$emit(detailItemImgLoad)
        // }
      },
      itemClick(){
        this.$router.push('/detail/' + this.goodsItem.iid)
      }
    }
  }
</script>

<style>
 .goods-item{
    padding-bottom: 2.5rem;
    position: relative;
    width: 9.375rem;
  }
  .goods-item img{
    width: 100%;
    border-radius: 0.3125rem;
  }

  .goods-info{
    font-size: 0.75rem;
    position: absolute;
    bottom: 0.3125rem;
    left: 0;
    right: 0;
    overflow: hidden;
    text-align: center;
  }

  .goods-info p{
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-bottom: 0.1875rem;
  }

  .goods-info .price{
    color: hotpink;
    margin-right: 1.25rem;
  }
  .goods-info .collect{
    position: absolute;
  }
  .goods-info .collect::before{
    content: '';
    position: absolute;
    left: -0.9375rem;
    top: -0.0625rem;
    width: 0.875rem;
    height: 0.875rem;
  }
</style>
